//
//  UIViewController+NetworkHUD.m
//  魔兽大数据
//
//  Created by 王右 on 2017/11/16.
//  Copyright © 2017年 王右. All rights reserved.
//

#import "UIViewController+NetworkHUD.h"


@implementation UIViewController (NetworkHUD)

- (void)hudWithText:(NSString *)text{
    [self removeHud];
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].delegate.window animated:YES];
    hud.minSize = CGSizeMake(100, 100);
    hud.label.text=text?text:@"加载中...";
    hud.label.font=[UIFont systemFontOfSize:15];
    hud.label.textColor= [UIColor whiteColor];
    hud.label.numberOfLines = 0;
    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    hud.bezelView.color = [UIColor colorWithWhite:0 alpha:0.9];
    hud.removeFromSuperViewOnHide = YES;
    [hud setContentColor:[UIColor whiteColor]];
}

- (void)removeHud{
    [MBProgressHUD hideHUDForView:[UIApplication sharedApplication].delegate.window animated:YES];
}


- (void)hudWithText:(NSString *)text onView:(UIView *)onView{
    [self removeHudOnView:onView];
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:onView animated:YES];
    hud.label.text = text;
    hud.label.textColor = [UIColor whiteColor];
}

- (void)removeHudOnView:(UIView *)onView{
    [MBProgressHUD hideHUDForView:onView animated:YES];
}

- (void)resetLeftBarButtonItem{
    UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)];
    button.frame = CGRectMake(0, 0, 44, 44);
    [button setImageEdgeInsets:UIEdgeInsetsMake(0, -20, 0, 0)];
    [button setImage:[UIImage imageNamed:@"back_b"] forState:(UIControlStateNormal)];
    [button setTintColor:[UIColor colorWithHexString:@"#57575c"]];
    [button setActionWithBlock:^(UIControl *control) {
        [self.navigationController popViewControllerAnimated:YES];
    }];
    UIBarButtonItem *bar = [[UIBarButtonItem alloc] initWithCustomView:button];
    self.navigationItem.leftBarButtonItem = bar;
}



@end
